# -*- coding: utf-8 -*- 
"""
========================================================================================================================
@project : my-sanic
@file: model
@Author: mengying
@email: 652044581@qq.com
@date: 2023/3/15 16:59
@desc: 定义你的数据结构层demo展示
========================================================================================================================
"""
from dataclasses import dataclass, field, asdict
from database.mongoClient import AsyncMongoMethod, SyncMongoMethod


@dataclass
class Student:
    price: int
    num: int = field(init=True)
    total: int = field(init=False, default="123", metadata={"desc": "总价"})

    def __post_init__(self):
        self.total = self.price * self.num

    @staticmethod
    def collection_name():
        return "test_database"


class StudentDao(AsyncMongoMethod):
    """
    使用方法：
        继承AsyncMongoMethod类方法， 需指定model的dataclass类和初始化数据时候
        也可以在这里重新定义自己的查询方式，和方法拓展
    """

    _model_class = Student

    @staticmethod
    def template(self):
        return asdict(Student(price=1, num=2))


class StudentDao2(SyncMongoMethod):
    """
    使用方法：
        继承AsyncMongoMethod类方法， 需指定model的dataclass类和初始化数据时候
        也可以在这里重新定义自己的查询方式，和方法拓展
    """

    _model_class = Student

    def template(self):
        return asdict(Student(price=1, num=2))
